From 386346950a2bf9c40e2d42c4b7032e12a40acf69 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Thu, 1 Sep 2005 09:37:54 +0000 Subject: [PATCH] Avoid code duplication between stringified and non-stringified asm macros, by stringifying on use where that is needed. Signed-off-by: Keir Fraser --- xen/include/asm-x86/asm_defns.h | 5 --- xen/include/asm-x86/bitops.h | 5 --- xen/include/asm-x86/x86_32/asm_defns.h | 50 ++---------------------- xen/include/asm-x86/x86_64/asm_defns.h | 54 +++----------------------- xen/include/xen/config.h | 3 ++ 5 files changed, 13 insertions(+), 104 deletions(-) diff --git a/xen/include/asm-x86/asm_defns.h b/xen/include/asm-x86/asm_defns.h index 17777ad123..c9ea4863a3 100644 --- a/xen/include/asm-x86/asm_defns.h +++ b/xen/include/asm-x86/asm_defns.h @@ -6,11 +6,6 @@ #include #include -#ifndef STR -#define __STR(x) #x -#define STR(x) __STR(x) -#endif - #ifdef __x86_64__ #include #else diff --git a/xen/include/asm-x86/bitops.h b/xen/include/asm-x86/bitops.h index 9682ec96da..8bf54fcdc3 100644 --- a/xen/include/asm-x86/bitops.h +++ b/xen/include/asm-x86/bitops.h @@ -7,11 +7,6 @@ #include -#ifndef STR -#define __STR(x) #x -#define STR(x) __STR(x) -#endif - /* * These have to be done with inline assembly: that way the bit-setting * is guaranteed to be atomic. All bit operations return 0 if the bit diff --git a/xen/include/asm-x86/x86_32/asm_defns.h b/xen/include/asm-x86/x86_32/asm_defns.h index 7ec44ec290..d0243d4a52 100644 --- a/xen/include/asm-x86/x86_32/asm_defns.h +++ b/xen/include/asm-x86/x86_32/asm_defns.h @@ -1,46 +1,6 @@ #ifndef __X86_32_ASM_DEFNS_H__ #define __X86_32_ASM_DEFNS_H__ -/* Maybe auto-generate the following two cases (quoted vs. unquoted). */ -#ifndef __ASSEMBLY__ - -#define __SAVE_ALL_PRE \ - "cld;" \ - "pushl %eax;" \ - "pushl %ebp;" \ - "pushl %edi;" \ - "pushl %esi;" \ - "pushl %edx;" \ - "pushl %ecx;" \ - "pushl %ebx;" \ - "testl $"STR(X86_EFLAGS_VM)","STR(UREGS_eflags)"(%esp);" \ - "jz 2f;" \ - "call setup_vm86_frame;" \ - "jmp 3f;" \ - "2:testb $3,"STR(UREGS_cs)"(%esp);" \ - "jz 1f;" \ - "mov %ds,"STR(UREGS_ds)"(%esp);" \ - "mov %es,"STR(UREGS_es)"(%esp);" \ - "mov %fs,"STR(UREGS_fs)"(%esp);" \ - "mov %gs,"STR(UREGS_gs)"(%esp);" \ - "3:" - -#define SAVE_ALL_NOSEGREGS(_reg) \ - __SAVE_ALL_PRE \ - "1:" - -#define SET_XEN_SEGMENTS(_reg) \ - "movl $("STR(__HYPERVISOR_DS)"),%e"STR(_reg)"x;" \ - "mov %e"STR(_reg)"x,%ds;" \ - "mov %e"STR(_reg)"x,%es;" - -#define SAVE_ALL(_reg) \ - __SAVE_ALL_PRE \ - SET_XEN_SEGMENTS(_reg) \ - "1:" - -#else - #define __SAVE_ALL_PRE \ cld; \ pushl %eax; \ @@ -50,7 +10,7 @@ pushl %edx; \ pushl %ecx; \ pushl %ebx; \ - testl $X86_EFLAGS_VM,UREGS_eflags(%esp); \ + testl $(X86_EFLAGS_VM),UREGS_eflags(%esp); \ jz 2f; \ call setup_vm86_frame; \ jmp 3f; \ @@ -83,8 +43,6 @@ #define PERFC_INCR(_name,_idx) #endif -#endif - #define BUILD_SMP_INTERRUPT(x,v) XBUILD_SMP_INTERRUPT(x,v) #define XBUILD_SMP_INTERRUPT(x,v) \ asmlinkage void x(void); \ @@ -92,7 +50,7 @@ __asm__( \ "\n"__ALIGN_STR"\n" \ STR(x) ":\n\t" \ "pushl $"#v"<<16\n\t" \ - SAVE_ALL(a) \ + STR(SAVE_ALL(a)) \ "call "STR(smp_##x)"\n\t" \ "jmp ret_from_intr\n"); @@ -103,7 +61,7 @@ __asm__( \ "\n"__ALIGN_STR"\n" \ STR(x) ":\n\t" \ "pushl $"#v"<<16\n\t" \ - SAVE_ALL(a) \ + STR(SAVE_ALL(a)) \ "movl %esp,%eax\n\t" \ "pushl %eax\n\t" \ "call "STR(smp_##x)"\n\t" \ @@ -114,7 +72,7 @@ STR(x) ":\n\t" \ __asm__( \ "\n" __ALIGN_STR"\n" \ "common_interrupt:\n\t" \ - SAVE_ALL(a) \ + STR(SAVE_ALL(a)) \ "movl %esp,%eax\n\t" \ "pushl %eax\n\t" \ "call " STR(do_IRQ) "\n\t" \ diff --git a/xen/include/asm-x86/x86_64/asm_defns.h b/xen/include/asm-x86/x86_64/asm_defns.h index 60fd76d14a..ff1d4927e0 100644 --- a/xen/include/asm-x86/x86_64/asm_defns.h +++ b/xen/include/asm-x86/x86_64/asm_defns.h @@ -1,50 +1,6 @@ #ifndef __X86_64_ASM_DEFNS_H__ #define __X86_64_ASM_DEFNS_H__ -/* Maybe auto-generate the following two cases (quoted vs. unquoted). */ -#ifndef __ASSEMBLY__ - -#define SAVE_ALL \ - "cld;" \ - "pushq %rdi;" \ - "pushq %rsi;" \ - "pushq %rdx;" \ - "pushq %rcx;" \ - "pushq %rax;" \ - "pushq %r8;" \ - "pushq %r9;" \ - "pushq %r10;" \ - "pushq %r11;" \ - "pushq %rbx;" \ - "pushq %rbp;" \ - "pushq %r12;" \ - "pushq %r13;" \ - "pushq %r14;" \ - "pushq %r15;" - -#define RESTORE_ALL \ - "popq %r15;" \ - "popq %r14;" \ - "popq %r13;" \ - "popq %r12;" \ - "popq %rbp;" \ - "popq %rbx;" \ - "popq %r11;" \ - "popq %r10;" \ - "popq %r9;" \ - "popq %r8;" \ - "popq %rax;" \ - "popq %rcx;" \ - "popq %rdx;" \ - "popq %rsi;" \ - "popq %rdi;" - -/* Work around AMD erratum #88 */ -#define safe_swapgs \ - "mfence; swapgs;" - -#else - #define SAVE_ALL \ cld; \ pushq %rdi; \ @@ -90,7 +46,9 @@ #define PERFC_INCR(_name,_idx) #endif -#endif +/* Work around AMD erratum #88 */ +#define safe_swapgs \ + "mfence; swapgs;" #define BUILD_SMP_INTERRUPT(x,v) XBUILD_SMP_INTERRUPT(x,v) #define XBUILD_SMP_INTERRUPT(x,v) \ @@ -100,7 +58,7 @@ __asm__( \ STR(x) ":\n\t" \ "pushq $0\n\t" \ "movl $"#v",4(%rsp)\n\t" \ - SAVE_ALL \ + STR(SAVE_ALL) \ "callq "STR(smp_##x)"\n\t" \ "jmp ret_from_intr\n"); @@ -112,7 +70,7 @@ __asm__( \ STR(x) ":\n\t" \ "pushq $0\n\t" \ "movl $"#v",4(%rsp)\n\t" \ - SAVE_ALL \ + STR(SAVE_ALL) \ "movq %rsp,%rdi\n\t" \ "callq "STR(smp_##x)"\n\t" \ "jmp ret_from_intr\n"); @@ -121,7 +79,7 @@ STR(x) ":\n\t" \ __asm__( \ "\n" __ALIGN_STR"\n" \ "common_interrupt:\n\t" \ - SAVE_ALL \ + STR(SAVE_ALL) \ "movq %rsp,%rdi\n\t" \ "callq " STR(do_IRQ) "\n\t" \ "jmp ret_from_intr\n"); diff --git a/xen/include/xen/config.h b/xen/include/xen/config.h index ca3650f80f..e59bb86a7c 100644 --- a/xen/include/xen/config.h +++ b/xen/include/xen/config.h @@ -40,4 +40,7 @@ #include #endif +#define __STR(...) #__VA_ARGS__ +#define STR(...) __STR(__VA_ARGS__) + #endif /* __XEN_CONFIG_H__ */ -- 2.30.2